import Net from 'network.js'


/**
 * 登录
 * 
 */
export const login = (jscode, callback) => {
  Net.post('/miniapp.bosslogin', {
    jscode,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}




/**
 * 获取商户信息 (hmily ) 
 */
export const getMerchantInfo = (callback) => {
  Net.get('/merchant.info', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}

/**
 * 发送报告信息 (hmily ) 
 */
export const sendReport = (qcode, report_id, callback) => {
  Net.get('/offical.sendReportTo', {
    qcode,
    report_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '发送中...')
}



/**
 * 获取检测列表 (hmily ) 
 */
export const getCheckList = (report_id,callback) => {
  Net.get('/merchant.checklist', {
    report_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/**
 * 获取商家二维码信息 (hmily ) 
 */
export const getBossQcodeInfo = (qcode, callback) => {
  Net.get('/merchant.qcodeInfo', {
    qcode
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}


/**
 * 创建工单 (hmily )
 * qcode 二维码
 * mileage 里程数
 * checktype 检查类型 
 */
export const reportCreate = (qcode, mileage, checktype, callback) => {
  Net.post('/report.create', {
    qcode,
    mileage,
    checktype,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}


/** 
 * 获取项目列表 (hmily ) 
 */
export const getMerchantCategory = (callback) => {
  Net.get('/merchant.pro_category', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}
/**
 * 提交选择的检查项 (hmily )
 * report_id 报告ID
 * qcode 二维码
 * checklist 选择的检查项 
 */
export const submitReportItems = (report_id, qcode, checklist, callback) => {
  Net.post('/report.items', {
    report_id,
    qcode,
    checklist
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}






/** 
 * 商户预览检测报告 (hmily )
 * report_id  报告id
 */
export const merchantReview = (report_id, callback) => {
  Net.get('/merchant.report.show', {
    report_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 获取注册时的 选项信息 (hmily )
 * id 商品ID
 */
export const getMerchantConfigs = (callback) => {
  Net.get('/merchant.configs', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 发送手机验证码 (hmily )
 */
export const smsSend = (mobile, callback) => {
  Net.post('/sms.send', {
    mobile
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}

/**
 * 商户注册 (hmily )
 * name	是	string	店铺名称
 * mobile	是	string	手机
 * verifyCode	是	string	验证码
 * address	否	string	地址
 * telephone	否	string	电话
 * master_name	否	string	店主名字
 * invitecode	否	string	客户经理邀请码
 * business	否	string	业务范围
 * workers	否	string	工人数量
 * scale	否	string	规模
 * blicense 营业执照
 */
export const merchantRegister = (name, mobile, verifyCode, address, telephone, master_name, invitecode, business, workers, scale, blicense, callback) => {
  Net.post('/merchant.regist', {
    name,
    mobile,
    verifyCode,
    address,
    telephone,
    master_name,
    invitecode,
    business,
    workers,
    scale,
    blicense
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}



/** 
 * 检查是否是普通会员 (hmily ) 
 */
export const getUserState = (callback) => {
  Net.get('/merchant.ismerchant', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/** 
 * 获取店员列表 (hmily ) 
 */
export const getMerchantStaffs = (callback) => {
  Net.get('/merchant.staffs', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}



/** 
 * 生成邀请码 (hmily ) 
 */
export const getQcodeInvite = (callback) => {
  Net.get('/merchant.qcode.invite', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/** 
 * 门店注册信息初始化 (hmily ) 
 */
export const getMerchantRoles = (mid, callback) => {
  Net.get('/merchant.roles', {
    mid
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}



/**
 * 加入店铺 (hmily )
 */
export const merchantJoin = (mid, uid, t, role, mobile, verifyCode, callback) => {
  Net.post('/merchant.join', {
    mid,
    uid,
    t,
    role,
    mobile,
    verifyCode,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}






/**
 * 添加服务项目 (hmily )
 * name	是	string	服务名称
 * price	是	string	价格
 * description	否	string	描述
 * category_id	否	string	分类id
 */
export const addServiceItem = (id, name, price, description, category_id, callback) => {
  Net.post('/merchant.service_items', {
    id,
    name,
    price,
    description,
    category_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}



/**
 * 添加分类 (hmily )
 * title	是	string	分类名称
 * memo	是	string	备注 
 */
export const addCategory = (title, memo, callback) => {
  Net.post('/merchant.pro_category', {
    title,
    memo,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}

/**
 * 删除项目 (hmily )
 */
export const delItem = (id, callback) => {
  Net.post('/merchant.service_items_del', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}


/**
 * 删除分类 (hmily )
 */
export const delCategory = (id, callback) => {
  Net.post('/merchant.pro_category_del', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}



/**
 * 删除套餐 (hmily )
 */
export const delPackage = (id, callback) => {
  Net.post('/merchant.service_package_del', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}




/** 
 * 套餐管理获取项目列表 (hmily ) 
 */
export const getPackage_items = (callback) => {
  Net.get('/merchant.pro_category', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}



/**
 * 获取套餐列表 (hmily )  已废除 
 */
export const getPackageList = (callback) => {
  Net.get('/merchant.service_package', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}


/**
 * 获取套餐＋充值卡列表 (hmily )
 */
export const getCardAndPackageList = (callback) => {
  Net.get('/merchant.card_packages', {}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}




/**
 * 保存套餐 (hmily )
 * name	是	string	套餐名称
 * price	是	string	价格
 * end	是	string	结束时间戳
 * package_id	是	string	套餐id
 * items	是	array	服务项目ids数组 [{“id”:13,”count”:773},{“id”:16,”count”:6}]
 */
export const savePackage = (name, price, end, package_id, items, description, callback) => {
  Net.post('/merchant.service_package', {
    name,
    price,
    end,
    package_id,
    items,
    description
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}



/**
 * 保存充值卡 (hmily )
 * charge	充值金额
 * give	赠送金额
 * description	充值描述
 * end_at	 有效期 
 */
export const saveCard = (id,charge,give,description,end_at, callback) => {
  Net.post('/merchant.cash_card', {
    id,
    charge,
    give,
    description,
    end_at
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}

/**
 * 获取会员卡信息，用于修改前的信息初始化 (hmily ) 
 */
export const getCardInfo = (id, callback) => {
  Net.get('/merchant.cash_card', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}





/**
 * 获取商品管理分类列表 (hmily ) 
 */
export const getStockCategoy = (id, callback) => {
  Net.get('/merchant.stock_categoys', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 获取添加商品分类列表信息 (hmily ) 
 */
export const getCategoryCheckList = (id, callback) => {
  Net.get('/merchant.stock_select_category', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/**
 * 添加商品 (hmily ) 
 * barcode 商品条形码
 * name 商品名称
 * service_item_id 商品对应项目
 * count 数量
 * threshold 库存预警值
 * in_price 进价
 * out_price 售价
 * memo 商品备注
 */
export const addProduct = (barcode, name, service_item_id, count, threshold, in_price, out_price, memo, pic, callback) => {
  Net.post('/merchant.stock', {
    barcode,
    name,
    service_item_id,
    count,
    threshold,
    in_price,
    out_price,
    memo,
    pic
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}


/**
 * 获取添加套餐时选的分类列表信息 (hmily ) 
 */
export const getProductInfoForBarcode = (barcode, callback) => {
  Net.get('/barcode.query', {
    barcode
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}


/**
 * 获取搜索结果 (hmily ) 
 */
export const getSearchInfo = (word, service_id, callback) => {
  Net.get('/merchant.stock.search', {
    word,
    service_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}

/**
 * 获取优惠券管理页面初始化信息 (hmily ) 
 */
export const getCouponConfigInfo = (id, callback) => {
  Net.get('/merchant.coupon.create', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}


/**
 * 创建优惠券 (hmily ) 
 * 
 * id
 *title   标题 （必须）
 *service_item_id    项目id
 *max  每个人最大持有量
 *money   金额
 *threshold  满减条件
 *start_at 开始日期
 *end_at = 结束日期
 *total 总量
 *valid_days  有效天数
 * description 描述
 */
export const submitCoupon = (id, title, service_item_id, max, money, threshold,
  start_at, end_at, total, valid_days, description, coupon_type, callback) => {
  Net.post('/merchant.coupon', {
    id,
    title,
    service_item_id,
    max,
    money,
    threshold,
    start_at,
    end_at,
    total,
    valid_days,
    description,
    coupon_type
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}

/**
 * 接车初始化信息 (hmily ) 
 */
export const getJieCheInitInfo = (qcode, callback) => {
  Net.get('/merchant.pickauto', {
    qcode
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}




/** 
 * 获取项目选择列表 (hmily ) 
 */
export const getMerchantPickerList = (user_id,callback) => {
  Net.get('/merchant.pick_serviceitem', { user_id}, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}



/**
 * 创建优惠券 (hmily ) 
 * 
 * id
 *title   标题 （必须）
 *service_item_id    项目id
 *max  每个人最大持有量
 *money   金额
 *threshold  满减条件
 *start_at 开始日期
 *end_at = 结束日期
 *total 总量
 *valid_days  有效天数
 * description 描述
 */
export const submitOpenOrder = (id, qcode, time_fee, items, callback) => {
  Net.post('/merchant.service_record', {
    id,
    qcode,
    time_fee,
    items,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}


/** 
 * 获取项目选择列表 (hmily ) 
 *  state :0 未完成，服务中，1 已完成
 */
export const getJieCheDanList = (state,page, callback) => {
  Net.get('/merchant.service_records', {
    state,
    page
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/** 
 * 获取消费项目详情 (hmily ) 
 * id : 订单id
 */
export const getOrderDetail = (id, callback) => {
  Net.get('/merchant.service_record', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '加载中...')
}

/** 
 * 提交支付方式 (hmily )  
 */
export const sendPayMethod = (service_record_id, payment_id, delay, callback) => {
  Net.post('/merchant.service_record.mark', {
    service_record_id,
    payment_id,
    delay
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/** 
 * 提交施工项目 (hmily )  
 */
export const sendShiGongPro = (service_record_id, service_item_ids, callback) => {
  Net.post('/merchant.join_service', {
    service_record_id,
    service_item_ids,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/** 
 * 提交销售人员 (hmily )  
 */
export const sendjoinSeller = (service_record_id, callback) => {
  Net.post('/merchant.join_as_seller', {
    service_record_id,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}

/** 
 * 取消订单 (hmily )  
 */
export const orderCancel = (id, callback) => {
  Net.post('/merchant.service_record_del', {
    id,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/** 
 * 发送通知 (hmily )  
 */
export const sendNotice = (id, callback) => {
  Net.post('/merchant.submit_service', {
    id,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/** 
 * 撤销施工 (hmily )  
 */
export const workerDel = (service_record_id, callback) => {
  Net.post('/merchant.service_record_worker_del', {
    service_record_id,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/** 
 * 获取服务项目 (hmily )  
 */

export const getServicesItems = (service_record_id, worker_id, callback) => {
  Net.get('/merchant.service_record_details', {
    service_record_id,
    worker_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '加载中...')
}



/** 
 * 获取检测项目详情 (hmily ) 
 * id : 订单id
 */
export const getCheckDetail = (id, callback) => {
  Net.get('/merchant.report.detail', {
    id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '加载中...')
}


/** 
 * 将自己添加为检测人 (hmily )  
 */

export const addChecker = (report_id, worker_ids, callback) => {
  Net.post('/merchant.report.checker', {
    report_id,
    worker_ids
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}





/** 
 * 获取检测项目 施工初始化信息 (hmily ) 
 * id : 订单id
 */
export const getBeginCheckInit = (report_id, callback) => {
  Net.get('/merchant.report.fixment', {
    report_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '加载中...')
}



/** 
 * 确认施工 (hmily )  
 */

export const confirmBeginCheck = (report_id, report_details, remind_days, callback) => {
  Net.post('/merchant.report.fixment', {
    report_id,
    report_details,
    remind_days,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/** 
 * 删除充值卡 (hmily )  
 */

export const cardDel = (card_id,callback) => {
  Net.post('/merchant.cash_card_del', {
    card_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
} 


/** 
 * 获取店员信息 (hmily ) 
 * id : 订单id
 */
export const getStaffInfo = (staff_id, callback) => {
  Net.get('/merchant.user_rp', {
    staff_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '加载中...')
}



/** 
 * 店员修改权限，修改职位 (hmily )  
 */

export const changeRankAndRole = (staff_id, rank_id, role_ids, callback) => {
  Net.post('/merchant.user_rp', {
    staff_id, rank_id, role_ids,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '修改中...')
}  


/** 
 * 删除店员 (hmily )  
 */

export const delStaff = (staff_id,callback) => {
  Net.post('/merchant.user_rp_del', {
    staff_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}   



/** 
 * 获取商户首页初始化 (hmily )  
 */
export const getHomeInit = (callback) => {
  Net.get('/merchant.home_page_icons', { 
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '加载中...')
}

/** 
 * 获取车辆管理车辆 (hmily )  
 */
export const getCarList = (page,callback) => {
  Net.get('/merchant.autos', {
    page
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '加载中...')
}


/** 
 * 获取优惠券列表 (hmily )  
 */
export const getCoupons = (callback) => {
  Net.get('/merchant.coupons', {
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '加载中...')
}


/** 
 * 获取优惠券信息 (hmily )  
 */
export const getCouponsDetail = (id,callback) => {
  Net.get('/merchant.coupon', {id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '加载中...')
} 



/** 
 * 发送优惠券 (hmily )  
 */
export const sendCoupon = (coupon_id, callback) => {
  Net.post('/merchant.coupon.send', {
    coupon_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}  



/** 
 * 添加车辆 (hmily )  
 */
export const addCar = (id, auto_number, name, phone, callback) => {
  Net.post('/merchant.auto', {
    id, auto_number, name, phone
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}  
 
/** 
 * 删除车辆 (hmily )  
 */
export const delCar = (id, callback) => {
  Net.post('/merchant.auto_del', {
    id,
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
} 


/** 
 * 获取车辆搜索结果 (hmily )  
 */
export const getSearchCar = (keyword, callback) => {
  Net.get('/merchant.autos_search', {
    keyword
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '搜索中...')
}
 

/** 
 * 获取搜索历史结果 (hmily )  
 */
export const getSearchHistorys = (callback) => {
  Net.get('/merchant.historys', { 
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '搜索中...')
}


/** 
 * 立即体验 (hmily )  
 */
export const getTiYan = (callback) => {
  Net.get('/experience_acount', {
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, false, '')
}



/**
 * 获取检测列表 (hmily ) 
 */
export const getChecks = (state,page, callback) => {
  Net.get('/merchant.reports', {
    state,
    page
  }, (r) => {
    callback(r);
  }, (e) => { console.log(e) }, {}, true, '加载中...')
}


/**
 * 获取保险信息 (hmily ) 
 */
export const getCarBaoxianInfo = (LicenseNo, callback) => {
  Net.get('/merchant.insurance', {
    LicenseNo
  }, (r) => {
    callback(r);
  }, (e) => { console.log(e) }, {}, true, '努力查找中...')
} 


/**
 * 获取保险信息 (hmily ) 
 */
export const getCarBaoXianList = (prm,page, callback) => {
  Net.get('/merchant.insurances', {
    prm,
    page
  }, (r) => {
    callback(r);
  }, (e) => { console.log(e) }, {}, true, '加载中...')
} 


/** 
 * 发送套餐办理到客户端 (hmily )  
 */
export const sendPackagrHandle = (qcode, package_id, payment_id, callback) => {
  Net.post('/merchant.package.toUser', {
    qcode, package_id, payment_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}  

/** 
 * 发送会员卡办理到客户端 (hmily )  
 */
export const sendCardHandle = (qcode, card_id, payment_id, callback) => {
  Net.post('/merchant.card.toUser', {
    qcode, card_id, payment_id
  }, (r) => {
    callback(r);
  }, (e) => {
    console.log(e)
  }, {}, true, '')
}  

/**
 * 套餐，充值卡线下支付获取支付方式 (hmily ) 
 */
export const getPayList = (callback) => {
  Net.get('/merchant.service_record.payments', { 
  }, (r) => {
    callback(r);
  }, (e) => { console.log(e) }, {}, true, '加载中...')
} 

